import components from 'ui/index';
import locale from '../locale/';
import { validatenull } from 'utils/validate.js';
import { vaildData, } from 'utils/util';



let prototypes = {
    validatenull,
    vaildData
};
const install = function (Vue, opts = {}) {
    // 初始化指令
    Object.keys(components).map(ele => {
        let component = components[ele];
        let name = component.name || '';
        name = name.substr(name.length - 1, 1) === '-' ? (name.substr(0, name.length - 1)) + ele : name;
        Vue.component(name, component);
    });
    // 常用方法挂在vue
    Object.keys(prototypes).forEach((key) => {
        Vue.prototype[key] = prototypes[key];
    });
    // 国际化
    locale.use(opts.locale);
    locale.i18n(opts.i18n);

    Vue.prototype.$axios = opts.axios || window.axios;
};

if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue);
}





export default install